<template>
    <h2>修改理财项目信息</h2>
    <table >
        <tr>
            <td>理财名称</td>
            <td><input type="text" v-model="info.F_name"></td>
        </tr>
        <tr>
            <td>年收益</td>
            <td><input type="text" v-model="info.F_APY"></td>
        </tr>
        <tr>
            <td>理财最低金额</td>
            <td><input type="text" v-model="info.F_MinMoney"></td>
        </tr>
        <tr>
            <td>风险等级</td>
            <td>
               <input type="radio" name="Flevel" value="0" v-model="info.F_Level" checked>低风险
               <input type="radio" name="Flevel" value="1" v-model="info.F_Level">中风险
               <input type="radio" name="Flevel" value="2" v-model="info.F_Level">高风险
            </td>
        </tr>
        <tr>
            <td>理财利率</td>
            <td>
               <select v-model="info.I_id">
                   <option value="0">==请选择==</option>
                   <option v-for="item in interestInfo" :value=item.I_id>{{item.I_year}}年利率为{{item.I_Interest}}%</option>
               </select>
            </td>
        </tr>
        <tr>
           <td colspan="2" style="text-align: center;">
               <input type="button" value="修改" class="btn btn-primary" @click="UpdateFinanInfo">
           </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'

import {useRoute,useRouter} from 'vue-router'

const route = useRoute()

const router = useRouter()
//alert(route.params.Fid)
//创建响应式数据
const info = ref({
    F_name:"",
    F_APY:"",
    F_MinMoney:"",
    F_Number:"",
    F_Level:0,
    I_id:0
})
//创建生命周期函数勾
onMounted(()=>{
    LoadInterestInfo();
    LoadFinanData();
})

//创建理财利息响应式数据
const interestInfo = ref([{
     I_id:0,
     I_year:0,
     I_Interest:0
}])

//理财利率
const LoadInterestInfo=()=>{
     axios.get("https://localhost:44337/api/Finans/ShowInterestInfo").then(res=>{
         interestInfo.value=res.data;
         console.log(res.data)
     }).catch(err=>{
         console.log(err)
     })
}

//反填理财项目信息
const LoadFinanData=() =>{
      axios({
         url:"https://localhost:44337/api/Finans/GetFinanInfo",
         method:"get",
         params:{
             Fid:route.params.Fid
         }
      }).then(res=>{
          console.log(res.data)
          info.value=res.data;
      }).catch(err=>{
          console.log(err)
      })
}

//修改理财项目信息
const UpdateFinanInfo=()=>{
      axios({
         url:"https://localhost:44337/api/Finans/UpdateFinanInfo",
         method:"put",
         data:info.value
      }).then(res=>{
          console.log(res.data)
          if(res.data>0){
              alert("修改成功")
              router.push('/ShowFinanInfo')
          }else{
              alert("修改失败")
          }
          
      }).catch(err=>{
          console.log(err)
      })
}
</script>